package com.cw2.behavioral.chain.ext;

/**
 * HttpFilter...doFilter之前
 * CharacterFilter...doFilter之前
 * EncodingFilter...doFilter之前
 * 调用my.hello()
 * EncodingFilter...doFilter之后
 * CharacterFilter...doFilter之后
 * HttpFilter...doFilter之后
 */
// 1---2---3--my---3---2---1
/**
 * 模拟filter - 责任链模式
 */
public class MainTest {
    public static void main(String[] args) {
        FilterChain filterChain = new FilterChain();

        HttpFilter httpFilter = new HttpFilter();
        CharacterFilter characterFilter = new CharacterFilter();
        EncodingFilter encodingFilter = new EncodingFilter();
        filterChain.addFilter(httpFilter);
        filterChain.addFilter(characterFilter);
        filterChain.addFilter(encodingFilter);

        filterChain.setTarget(new My());

        filterChain.doFilter(new Request("request"), new Response("response"), filterChain);

    }
}
